/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const urlencode = require("urlencode")

/**
 * 北京互金网
 * @type {module.Bjp2p}
 */
module.exports = class UCoinJson extends BaseJsonAdapter{


    async reqJson(){
		const body = await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();
        decodeBody = urlencode.decode(decodeBody,this.encoding);
        // decodeBody = decodeBody.replace(/\\/g,'');
        // decodeBody = decodeBody.substr(1,decodeBody.length-2);
        let data = JSON.parse(decodeBody);
        let urlPre = "https://www.ucoin.pw/news/detail/";
        for (let i=0;i<data.data.length;i++) {
            data.data[i].url=urlPre+data.data[i].id;
        }
        console.log("-----decodeBody: " + decodeBody)
		return data;
	}
}
